package com.ruoyi.web.controller.activity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activity.domain.ActApply;
import com.ruoyi.activity.service.IActApplyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动申请Controller
 * 
 * @author YZD
 * @date 2022-07-12
 */
@Controller
@RequestMapping("/activity/apply")
public class ActApplyController extends BaseController
{
    private String prefix = "activity/apply";

    @Autowired
    private IActApplyService actApplyService;

    @RequiresPermissions("activity:apply:view")
    @GetMapping()
    public String apply()
    {
        return prefix + "/apply";
    }

    /**
     * 查询活动申请列表
     */
    @RequiresPermissions("activity:apply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActApply actApply)
    {
        startPage();
        List<ActApply> list = actApplyService.selectActApplyList(actApply);
        return getDataTable(list);
    }

    /**
     * 导出活动申请列表
     */
    @RequiresPermissions("activity:apply:export")
    @Log(title = "活动申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActApply actApply)
    {
        List<ActApply> list = actApplyService.selectActApplyList(actApply);
        ExcelUtil<ActApply> util = new ExcelUtil<ActApply>(ActApply.class);
        return util.exportExcel(list, "活动申请数据");
    }

    /**
     * 新增活动申请
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存活动申请
     */
    @RequiresPermissions("activity:apply:add")
    @Log(title = "活动申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActApply actApply)
    {
        actApply.setTime(new Date());
        return toAjax(actApplyService.insertActApply(actApply));
    }

    /**
     * 修改活动申请
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ActApply actApply = actApplyService.selectActApplyById(id);
        mmap.put("actApply", actApply);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动申请
     */
    @RequiresPermissions("activity:apply:edit")
    @Log(title = "活动申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActApply actApply)
    {
        return toAjax(actApplyService.updateActApply(actApply));
    }

    /**
     * 删除活动申请
     */
    @RequiresPermissions("activity:apply:remove")
    @Log(title = "活动申请", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(actApplyService.deleteActApplyByIds(ids));
    }
}
